package main

import (
	"fmt"
	"reflect"
)

type Student struct {
	name string
	age byte
}

func reflectTest(a interface{}) {
	/*
		tips:
			在运行时，可以确定interface{}的确定类型，但是在编译时，类型是interface{}
		ps. 通过类型断言的方式，获取运行时类型
	*/
	fmt.Printf("a val %v, type is %[1]T\n", a)
	// fmt.Println(a.name) // a.name undefined (type interface {} is interface with no methods)
	stu := a.(Student)
	fmt.Println(stu.name) // jack

	fmt.Println("----------------------")

	rType := reflect.TypeOf(a)
	fmt.Printf("rType val is %v, type is %[1]T\n", rType)
	// rType val is main.Student, type is *reflect.rtype

	rVal := reflect.ValueOf(a)
	fmt.Printf("rVal val is %v, type is %[1]T\n", rVal)
	// rVal val is {jack 12}, type is reflect.Value

	fmt.Println("kind is ", rType.Kind(), rVal.Kind()) // kind is  struct struct
}

func main() {
	stu := Student{
		name: "jack",
		age: 12,
	}
	reflectTest(stu)
}
